package managedbean;

import entity.SaleLead;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import session.stateless.SaleLeadBeanLocal;

@ManagedBean
@ViewScoped

public class EditSaleLeadManagerBean implements Serializable
{
    @EJB
    private SaleLeadBeanLocal saleLeadBeanLocal;
    private SaleLead saleLeadToEdit;
    
    public SaleLead getSaleLeadToEdit() {
        return saleLeadToEdit;
    }
    public void setSaleLeadToEdit(SaleLead saleLeadToEdit) {
        this.saleLeadToEdit = saleLeadToEdit;
    }
    
    public EditSaleLeadManagerBean() {}
    
    public void initView(PhaseEvent event)
    {
        if(saleLeadToEdit == null)
        {            
            saleLeadToEdit = (SaleLead)FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedSaleLead");            
        }
    }
    
    public void updateExistingSaleLead(ActionEvent event)
    {
        System.out.println("********* " + saleLeadToEdit.getSaleLeadName());
        saleLeadBeanLocal.updateSaleLead(saleLeadToEdit.getSaleLeadId(), saleLeadToEdit.getSaleLeadName(), saleLeadToEdit.getSaleLeadNRIC(), saleLeadToEdit.getSaleLeadEmail(), saleLeadToEdit.getSaleLeadAddress(), saleLeadToEdit.getSaleLeadContactNumber(), saleLeadToEdit.getCustomerType());
    }    
}
